package com.smartrobot.util;

import java.util.Properties;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ConvUtil {
	private static ApplicationContext context;
	
	private static Properties prop=new Properties();
	
	public static void initProp(){
		prop.put("GtalkIP", "talk.google.com");
		prop.put("GtalkPort", "80");
		prop.put("GtalkDomain", "gmail.com");
		prop.put("GtalkRobotID", "deployment.robot@gmail.com");
		prop.put("GtalkPassword", "deploymentrobot");
	}
	
	public static ApplicationContext getSpringContext() {
		if (context == null) {
			context = new ClassPathXmlApplicationContext(
					"com/smartrobot/config/applicationContext.xml");
		}
		
		return context;
	}
	
	public static String getProperty(String key){
		return prop.getProperty(key);
	}
	
	public static String splitMessage(String mess,int pos){
		if(!mess.contains(" ")){
			return mess;
		}else{
			String[] splits=mess.split(" ");
			if(splits.length< (pos-1)){
				return mess;
			}else{
				return mess.substring(mess.indexOf(splits[pos-1]));
			}
			
		}
		
	}
	
//	private static StackExchangeApiClientFactory factory;
//    private static StackExchangeApiClient client;
//    
//    public static StackExchangeApiClient getStackExchangeApiClient(){
//    	if(client==null){
//    		factory = StackExchangeApiClientFactory.newInstance("C9uyDMP_i0u1y7mXhB1GkQ");
//    		client = factory.createStackExchangeApiClient();
//    	}
//    		return client;
//    }
}
